import request from '@/utils/request'
import {Message } from 'element-ui'
import { error } from 'util'

// 获取用户list
export function getUsers(data, succCb) {
  return request({
    url: 'users/',
    method: 'get',
    params: data
  }).then(res => {
    succCb(res)
  }).catch(() => {
    console.log('getUsers-->>')
  })
}

// 获取用户Select
export function getUsersSelect(succCb) {
  return request({
    url: 'users/selectable',
    method: 'get'
  }).then(res => {
    succCb(res)
  }).catch(() => {
    console.log('getUsersSelect-->>')
  })
}

// 添加用户
export function addUser(data, succCb) {
  return request({
    url: 'users/',
    method: 'post',
    data
  }).then(res => {
    succCb(res)
  }).catch(() => {
    console.log('addUser-->>')
  })
}

// 删除用户
export function delUser(id, succCb) {
  return request({
    url: 'users/' + id,
    method: 'delete'
  }).then(res => {
    succCb(res)
  }).catch(() => {
    console.log('delUser-->>')
  })
}

// 用户组详情
export function UserDetail(id, succCb) {
  return request({
    url: 'users/' + id,
    method: 'get'
  }).then(res => {
    succCb(res)
  }).catch(() => {
    console.log('UserDetail-->>')
  })
}

// 更新用户组
export function updateUser(id, data, succCb) {
  return request({
    url: 'users/' + id,
    method: 'put',
    data
  }).then(res => {
    succCb(res)
  }).catch(() => {
    console.log('updateUser-->>')
  })
}

// 获取角色list
export function getRoles(succCb) {
  return request({
    url: 'roles/',
    method: 'get'
  }).then(res => {
    succCb(res)
  }).catch(() => {
    console.log('-->>users-get')
  })
}

// 修改密码
export function updateUserPwd(data, succCb) {
  return request({
    url: 'users/info',
    method: 'put',
    data
  }).then(res => {
    succCb(res)
  }).catch(() => {
    console.log('updateUserPwd-->>')
  })
}